package com.csxh.web.filter;

import java.io.IOException;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

import com.csxh.web.util.WebUtil;

/**
 * Servlet Filter implementation class JspFilter
 */
@WebFilter(
		urlPatterns={"*.jsp"},
        dispatcherTypes={DispatcherType.REQUEST,DispatcherType.INCLUDE}
        )
public class JspFilter implements Filter {

    /**
     * Default constructor. 
     */
    public JspFilter() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		request.getServletContext().log("拦截:"+request.getServletContext().getContextPath());
		//在处理*.jsp请求之前选执行*.servlet请求
		WebUtil.handleFilter(request, response, ".servlet");
        
		// pass the request along the filter chain
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
